﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.Model;
using Aij1.BLL;
using Aij1.Cms;
using System.Web.UI.HtmlControls;
using System.Text;

namespace Aij1
{
    public partial class _Default : BasePage
    {
        IList<A_Article> topAlbums;
        int topAlbumCount = 10;
        protected void Page_Load(object sender, EventArgs e)
        {
            R.DataSource = MenuData.GetClientMenus(XpoSession, MenuPositionType.主导航);
            R.DataBind();
            RA.DataSource = ArticleData.GetTopNews(XpoSession, "2", 4);
            RA.DataBind();

            Keywords = Config.Keywords;
            Description = Config.Description;

            //6=亲子相册
            topAlbums = AlbumData.GetTopAlbum(XpoSession, topAlbumCount + 1, 6);
        }

        public string GetTopAlbumHtml(int w, int h)
        {
            StringBuilder sb = new StringBuilder();
            int i = 0;
            foreach (A_Article album in topAlbums.Skip(1))
            {
                sb.Append(QBind.GetAlbumHtml(album, w, h));
                i++;
            }

            for (; i < topAlbumCount; i++)
            {
                sb.Append(QBind.GetAlbumHtml(null, w, h));
            }
            return sb.ToString();
        }

        string GetAlbumHtml(A_Article album, int divW, int divH)
        {
            return QBind.GetAlbumHtml(album, divW, divH);
        }

        public string GetWeekStartAlbumHtml(int divW, int divH)
        {
            A_Article weekStarAlbum = null;
            if (topAlbums.Count > 0)
            {
                weekStarAlbum = topAlbums[0];
            }
            return QBind.GetAlbumHtml(weekStarAlbum, divW, divH);
        }

        protected string FriendLink()
        {
            IList<G_FriendLink> links = AuthData.GetVisibleFriendLink(XpoSession);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 20; i++)
            {
                if (i < links.Count)
                {
                    sb.AppendFormat("<a href='{0}' taget='_blank'>{1}</a>", links[i].Url, links[i].Visible, links[i].Title);
                }
            }

            return sb.ToString();
        }
    }
}